source("R/00_custom_functions.R")

library(glue)
library(patchwork)



hd_ms_da12 <-  read_rds("data/SC/sim/HD_ms-parallel/plans_da12.rds")
hd_ms_da04 <-  read_rds("data/SC/sim/HD_ms-parallel/plans_da04.rds")
hd_ms_orig <-  read_rds("data/SC/sim/HD_ms-parallel/plans_orig.rds")

hd_st_da12 <-  read_rds("data/SC/sim/SMC-trunc/plans_da12.rds")
hd_st_da04 <-  read_rds("data/SC/sim/SMC-trunc/plans_da04.rds")
hd_st_orig <-  read_rds("data/SC/sim/SMC-trunc/plans_orig.rds")

cd_plans_da12 <-  read_rds("data/SC/sim/CD/plans_da12.rds")
cd_plans_da04 <-  read_rds("data/SC/sim/CD/plans_da04.rds")
cd_plans_orig <-  read_rds("data/SC/sim/CD/plans_orig.rds")

sc_map_orig <- read_rds("data/SC/sim/HD_ms-parallel/redist_map_orig.rds")


diag_out <-
    hist_VIdist(hd_ms_orig, "SC HDs Census 2010\n(**mergesplit-par**)") +
    hist_VIdist(hd_ms_da12, "SC HDs DAS-12.2\n(**mergesplit-par**)") +
    hist_VIdist(hd_ms_da04, "SC HDs DAS-4.5\n(**mergesplit-par**)") +
    hist_VIdist(hd_st_orig, "SC HDs Census 2010\n(**SMC-truncated**)") +
    hist_VIdist(hd_st_da12, "SC HDs DAS-12.2\n(**SMC-truncated**)") +
    hist_VIdist(hd_st_da04, "SC HDs DAS-4.5\n(**SMC-truncated**)") +
    hist_VIdist(cd_plans_orig, "SC **CDs** Census 2010\n(SMC)") +
    hist_VIdist(cd_plans_da12, "SC **CDs** DAS-12.2\n(SMC)") +
    hist_VIdist(cd_plans_da04, "SC **CDs** DAS-4.5\n(SMC)") +
    # hist_VIdist(nc_plans_orig, "**NC** CDs Census 2010\n(SMC)", map = nc_map_orig) +
    # hist_VIdist(nc_plans_da12, "**NC** CDs DAS-12.2\n(SMC)", map = nc_map_orig) +
    # hist_VIdist(nc_plans_da04, "**NC** CDs DAS-4.5\n(SMC)", map = nc_map_orig) +
    plot_layout(nrow = 3)


ggsave("figs/VI-diagnostics_SC-NC.pdf", diag_out, w = 7, h = 5)

